package cn.krund.lyc.hotlerobot.activity.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.krund.lyc.hotlerobot.R;
import cn.krund.lyc.hotlerobot.activity.base.BaseActivity;
import cn.krund.lyc.hotlerobot.activity.view.SerachSelectDialog;
import cn.krund.lyc.hotlerobot.utils.DeviceIdUtil;
import cn.krund.lyc.hotlerobot.utils.FileUtils;
import cn.krund.lyc.hotlerobot.utils.KrundLog;
import cn.krund.lyc.hotlerobot.utils.MD5Util;
import cn.krund.lyc.hotlerobot.utils.ToastUtils;

/**
 * @包名: cn.krund.lyc.hotlerobot.activity.ui
 * @作者: 刘育成
 * @时间: 2018/3/21  15:42
 * @org: 克路德人工智能
 * @描述: TODO
 * @fileName: LoginActivity
 */

public class LoginActivity extends BaseActivity implements View.OnClickListener {
    private TextView tv_address, tv_id;
    private List<String> mDatas;
    private Button btn_login;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    protected void initView() {
        tv_address = (TextView) findViewById(R.id.tv_address);
        btn_login = (Button) findViewById(R.id.btn_login);
        btn_login.setOnClickListener(this);
        tv_address.setOnClickListener(this);
        tv_id = (TextView) findViewById(R.id.tv_id);
    }

    @Override
    protected void initNev() {
        String id = MD5Util.MD5(DeviceIdUtil.getLocalMacAddressFromBusybox());
        tv_id.setText(id);
        mDatas = new ArrayList<>();
        String[] citys = {"武汉", "北京", "上海", "深圳", "兰州", "成都", "天津"};
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < citys.length; j++) {
                mDatas.add(citys[j] + i);
            }
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_address:
                SerachSelectDialog.Builder alert = new SerachSelectDialog.Builder(this);
                alert.setListData(mDatas);
                alert.setSelectedListiner(new SerachSelectDialog.Builder.OnSelectedListiner() {
                    @Override
                    public void onSelected(String info) {
                        tv_address.setText(info);
                    }
                });
                SerachSelectDialog mDialog = alert.show();
                //设置Dialog 尺寸
                mDialog.setDialogWindowAttr(0.7, 0.9, this);
                break;
            case R.id.btn_login:
                if (TextUtils.isEmpty(tv_address.getText())) {
                    ToastUtils.showLongToast(LoginActivity.this, "请先选择地址");
                } else {
                    KrundLog.d("lyc:::address>>>>>>>", tv_address.getText().toString());
                    openActivity(SysPasswordActivity.class);
                    finish();
//                    FileUtils.crFile("map");
//                    FileUtils.crFiles("map");
                }

                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
